package com.guoxin.concurrentprogramming.chapter6;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author guoxin
 * @date 2019/9/19
 */
public class AsynCompletableFuture {

    public static Integer calc(Integer para) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return para * para;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        final CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> calc(50));
//        System.out.println(future.get());
        final CompletableFuture<Void> fu = CompletableFuture.supplyAsync(() -> calc(50))
                .thenApply((i) -> Integer.toString(i))
                .thenApply((str) -> "\"" +str+ "\"")
                .thenAccept(System.out::println);
        fu.get();
    }
}
